package com.rc.saas.mini.config;

import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Primary;

import java.util.HashMap;
import java.util.Map;

/**
 * RabbitMQ配置
 * Created by sven on 2019/10/14
 */
@Configuration
//@ImportResource(locations = {"classpath:config/applicationContext-rabbitmq.xml"})
public class RabbitMqConfig {
    //
    //public static final int DEFAULT_CONCURRENT = 1;
    //@Bean
    //@Primary
    //public ConnectionFactory firstConnectionFactory(
    //        @Value("${spring.rabbitmq.host}") String host,
    //        @Value("${spring.rabbitmq.port}") int port,
    //        @Value("${spring.rabbitmq.username}") String username,
    //        @Value("${spring.rabbitmq.password}") String password,
    //        @Value("${spring.rabbitmq.virtual-host}") String virtualHost
    //) {
    //
    //    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    //    connectionFactory.setHost(host);
    //    connectionFactory.setPort(port);
    //    connectionFactory.setUsername(username);
    //    connectionFactory.setPassword(password);
    //    connectionFactory.setVirtualHost(virtualHost);
    //    return connectionFactory;
    //}
    //
    //@Bean
    //@Primary
    //public RabbitTemplate amqpTemplate(
    //        ConnectionFactory connectionFactory
    //) {
    //    RabbitTemplate firstRabbitTemplate = new RabbitTemplate(connectionFactory);
    //    return firstRabbitTemplate;
    //}
    //
    //@Bean
    //public SimpleRabbitListenerContainerFactory firstFactory(
    //        SimpleRabbitListenerContainerFactoryConfigurer configurer,
    //        //@Qualifier("firstConnectionFactory")
    //        ConnectionFactory connectionFactory
    //) {
    //    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    //    configurer.configure(factory, connectionFactory);
    //    return factory;
    //}
    //
    //
    //
    //@Bean("customContainerFactory")
    //public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
    //                                                             ConnectionFactory connectionFactory) {
    //    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    //    factory.setConcurrentConsumers(DEFAULT_CONCURRENT);
    //    factory.setMaxConcurrentConsumers(DEFAULT_CONCURRENT);
    //    factory.setPrefetchCount(250);
    //    configurer.configure(factory, connectionFactory);
    //    return factory;
    //}
}
